﻿package com.CameraCropTest;

public class Log {
	static String tag = new String();
	static String msg = new String();
	static boolean release = false;

	public static void l2(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString2(e);
		android.util.Log.e(tag, "f :" + getArgs(args) + msg);
		getString(e);
		android.util.Log.e(tag, "f :" + getArgs(args) + msg);
	}

	public static void e(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "!!:" + getArgs(args) + msg);
		e.printStackTrace();
	}

	public static void w(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "! :" + getArgs(args) + msg);
		e.printStackTrace();
	}

	public static void l() {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "f :" + msg);
	}

	public static void l(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "f :" + getArgs(args) + msg);
	}

	public static void c(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "? :" + getArgs(args) + msg);
		e.printStackTrace();
	}

	public static void d(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "d :" + getArgs(args) + msg);
	}

	public static void v(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "v :" + getArgs(args) + msg);
	}

	public static void i(Object... args) {
		if(release) return;
		Exception e = new Exception();
		getString(e);
		android.util.Log.e(tag, "i :" + getArgs(args) + msg);
	}

	private static String getArgs(final Object[] args) {
		StringBuffer sb = new StringBuffer();
		for (Object object : args) {
			sb.append(",");
			if (object == null)
				object = "null";
			sb.append(object.toString());
		}
		return sb.toString();
	}

	private static void getString(final Exception e) {
		String funcStack = e.getStackTrace()[1].toString();

		int posJava = funcStack.lastIndexOf("(");
		int posFunc = funcStack.lastIndexOf(".", posJava - 1);
		int posClass = funcStack.lastIndexOf(".", posFunc - 1);
		tag = funcStack.substring(posClass + 1, posJava);// classfuncName
		msg = ":at " + funcStack.substring(posJava);// javaName
	}

	private static void getString2(final Exception e) {
		String funcStack = e.getStackTrace()[2].toString();

		int posJava = funcStack.lastIndexOf("(");
		int posFunc = funcStack.lastIndexOf(".", posJava - 1);
		int posClass = funcStack.lastIndexOf(".", posFunc - 1);
		tag = funcStack.substring(posClass + 1, posJava);// classfuncName
		msg = ":at " + funcStack.substring(posJava);// javaName
	}

}
